<!--suppress ALL-->
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <title>layuiAdmin 网站用户 iframe 框</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="/layuiadmin/layui/css/layui.css" media="all">
    <link id="layuicss-layer" rel="stylesheet"
          href="https://www.layui.com/admin/std/dist/layuiadmin/layui/css/modules/layer/default/layer.css?v=3.1.1"
          media="all">
</head>
<body layadmin-themealias="default">

<form class="layui-form">
    <div class="layui-form" lay-filter="layuiadmin-form-useradmin" id="layuiadmin-form-useradmin"
         style="padding: 20px 0 0 0;">

        <div class="layui-form-item">
            <label class="layui-form-label">角色英文名:</label>
            <div class="layui-input-inline">
                <input type="text" name="qName" th:value="${role.name}" lay-verify="required" placeholder="如ROLE_ADMIN、ROLE_USER" autocomplete="off"
                       class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">角色名字:</label>
            <div class="layui-input-inline">
                <input type="text" name="nameZH" th:value="${role.nameZH}" lay-verify="required" placeholder="如用户、帮客" autocomplete="off"
                       class="layui-input">
                <input type="hidden" th:value="${role.id}" name="id">
            </div>
        </div>

        <!--<div class="layui-form-item">
            <label class="layui-form-label">用户角色:</label>
            <div class="layui-input-block" >
                <input th:each="role : ${roleAll}" type="checkbox" name="roles" th:title="${role.nameZH}" th:value="${role.id}">
            </div>
        </div>-->
        <div class="layui-form-item">
            <label class="layui-form-label">角色权限:</label>
            <div class="layui-input-block" >
                <input th:each="menu : ${menuList}" type="checkbox"
                       th:checked="${integerList.contains(menu.id)}" name="menus"
                       th:title="${menu.menuName}" th:value="${menu.id}">
            </div>
        </div>

       <!-- <div class="layui-form-item">
            <label class="layui-form-label">开关-默认开</label>
            <div class="layui-input-block">
                <input type="checkbox" checked="" name="open" lay-skin="switch" lay-filter="switchTest" lay-text="ON|OFF">
            </div>
        </div>-->
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit lay-filter="formDemoTi">立即提交</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </div>
</form>
<script src="/layuiadmin/layui/layui.js"></script>
<script th:inline="none">
    //添加数据功能
    layui.use(['form','layer','jquery'], function(){
        var form = layui.form
            ,layer = layui.layer
            ,$=layui.jquery,
            table= layui.table
        //监听提交
        form.on('submit(formDemoTi)', function(data){

            //权限数组
            var arr = new Array();
            $("input:checkbox[name='menus']:checked").each(function(i){
                arr[i] = $(this).val();
            });
            data.field.menus = arr.join(",");//将数组合并成字符串

            $.ajax({
                url:'/updateMenuRole',
                type:'POST',
                dataType:'json',
                data:{
                    nameZH:data.field.nameZH,
                    name:data.field.qName,
                    menus: data.field.menus,
                    rid:data.field.id
                },
                success:function (msg) {
                    var returnCode=msg.code;
                    if(returnCode===200){
                        layer.closeAll('loading');
                        layer.load(2);
                        layer.msg("修改成功", {icon: 6});
                        setTimeout(function(){
                            window.parent.location.reload();//修改成功后刷新父界面
                        }, 1000);
                        //加载层-风格

                    }else{
                        layer.msg("已经存在该设备,不支持重复添加", {icon: 5});
                    }
                }
            })
            return false;
        });
    });
</script>
<style id="LAY_layadmin_theme">.layui-side-menu, .layadmin-pagetabs .layui-tab-title li:after, .layadmin-pagetabs .layui-tab-title li.layui-this:after, .layui-layer-admin .layui-layer-title, .layadmin-side-shrink .layui-side-menu .layui-nav > .layui-nav-item > .layui-nav-child {
    background-color: #20222A !important;
}

.layui-nav-tree .layui-this, .layui-nav-tree .layui-this > a, .layui-nav-tree .layui-nav-child dd.layui-this, .layui-nav-tree .layui-nav-child dd.layui-this a {
    background-color: #009688 !important;
}

.layui-layout-admin .layui-logo {
    background-color: #20222A !important;
}</style>
</body>
</html>